package com.ranshiyan.controller;

import com.ranshiyan.entity.User;
import com.ranshiyan.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("user")
public class UserController {

    @Autowired
    private UserService userService;

    //登录
    @PostMapping("login")
    public String  login(User user, HttpSession session){
        User login = userService.login(user);
        if(login!=null){
            session.setAttribute("user",login);
            return "redirect:/file/findAll";
        }else{
            return "redirect:/login";
        }
    }
}
